package org.example.what_mall.result;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.what_mall.exception.GlobalCode;


@Data
@NoArgsConstructor
@AllArgsConstructor
public class HttpResult<T> {
    @Schema(description = "状态码")
    private int code;
    @Schema(description = "返回信息")
    private T data;

    public static <T> HttpResult<T> success(T data) {
        return new HttpResult<>(GlobalCode.SUCCESS.getCode(), data);
    }

    public static <Void> HttpResult<Void> ok()
    {
        return new HttpResult<>(GlobalCode.OK.getCode(), null);
    }

    public static <T> HttpResult<T> success() {
        return new HttpResult<>(GlobalCode.SUCCESS.getCode(), null);
    }

    public static <T> HttpResult<T> error(int code) {
        return new HttpResult<>(code, null);
    }

    public static <T> HttpResult<T> error(int code, T msg) {
        return new HttpResult<>(code, msg);
    }

}
